/******************************************************************************
** File Name:      bmpacket.h                                            *
** Author:         Apple Gao                                                 *
** DATE:           07/07/2004                                                *
** Copyright:      Spreatrum, Incoporated. All Rights Reserved.              *
** Description:    This files contains dll interface.                        *
******************************************************************************

  ******************************************************************************
  **                        Edit History                                       *
  ** ------------------------------------------------------------------------- *
  ** DATE				NAME				DESCRIPTION                       *
  ** 07/07/2004			Apple Gao			Create.							  * 
******************************************************************************/

/**---------------------------------------------------------------------------*
**                         Dependencies                                      *
**---------------------------------------------------------------------------*/

#ifndef _BMDATAPACKET_H
#define	_BMDATAPACKET_H

#define PART_PACKET     2
#define GOOD_PACKET     1
#define ERROR_PACKET    0 


//CRC
#define CRC_16_POLYNOMIAL       0x1021
#define CRC_16_L_POLYNOMIAL     0x8000
#define CRC_16_L_SEED           0x80
#define CRC_16_L_OK             0x00
#define HDLC_FLAG               0x7E
#define HDLC_ESCAPE             0x7D
#define HDLC_ESCAPE_MASK        0x20
#define CRC_CHECK_SIZE          0x02
#define CRC_TAB_SIZE            256   


///////////////////////////////////////////////////////////
int encode_msg(char* input_buf, int input_size, 
                         char **output_buf, int *output_len, int bcrc);
int decode_msg(char* input_buf, int input_size, 
                         char **output_buf, int *output_len,int bcrc);


unsigned int crc_16_l_calc (char *buf_ptr,unsigned int len);

unsigned short frm_chk (const unsigned short *src, int len);
unsigned long Get_CheckSum (const unsigned char *src, int len);
/**
 * crc16 - compute the CRC-16 for the data buffer
 * @crc:        previous CRC value
 * @buffer:     data pointer
 * @len:        number of bytes in the buffer
 *
 * Returns the updated CRC value.
 */
 
unsigned short crc16(unsigned short crc, 
                     unsigned char const *buffer,
                     unsigned int len);

int decode_bmmsg( unsigned char* lpSrcMsg, 
    int nSrcMsgLen,
    unsigned char** lppDestMsg,
    int *pnDestMsg ,
    int bCrc );

int encode_bmmsg(  unsigned char* lpSrcMsg, 
    int nSrcMsgLen,
    unsigned char** lppDestMsg,
    int *pnDestMsg,
    int bCrc );

#endif // _LOGELSIDEDPS_H